<!DOCTYPE html>
<title>Service Worker: timezonechange event</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
<script>
promise_test(t => {
    const script = 'resources/service-worker-timezonechange.js';
    const scope = 'resources/blank.html';
    let worker;
    let port;

    return service_worker_unregister_and_register(t, script, scope)
      .then(registration => {
          t.add_cleanup(() => registration.unregister());
          worker = registration.installing;

          const messageChannel = new MessageChannel();
          port = messageChannel.port1;
          return new Promise(resolve => {
              port.onmessage = resolve;
              worker.postMessage({port: messageChannel.port2},
                                 [messageChannel.port2]);
            });
        })
      .then(e => {
          assert_equals(e.data, 'READY');
          // Change the timezone once the service worker is ready.
          internals.setSystemTimeZone('Asia/Taipei');
          return new Promise(resolve => { port.onmessage = resolve; });
        })
      .then(e => {
          assert_equals(e.data, 'SUCCESS');
        });
  }, 'timezonechange event work in ServiceWorker');
</script>
